import instance from '@/request/request'

/**
 * 分页查询分类列表
 * @param params 包括 page(当前页) pageSize(每页条数) 条件信息
 * @returns {*}
 * @constructor
 */
export const GetCategoryPageApi = (params) => {
  return instance({
    url: '/api/category/page',
    method: 'get',
    params:params
  })
}

/**
 * 查询父级分类信息
 * @param level 分类等级
 * @returns {*}
 * @constructor
 */
export  const  GetCategoryParentApi=(level)=>{
  return instance({
    url: `/api/category/parent/${level}`,
    method: 'get'
  })
}
export  const  GetCategoryByParentAndLevelApi=(parent,level)=>{
  return instance({
    url: `/api/category/${parent}/${level}`,
    method: 'get'
  })
}
/**
 * 查询所有父级分类信息
 * @returns {*}
 * @constructor
 */
export  const  GetAllCategoryParentApi=()=>{
  return instance({
    url: `/api/category/parent`,
    method: 'get'
  })
}
/**
 * 添加分类信息
 * @param data 分类数据
 * @returns {*}
 * @constructor
 */
export  const AddCategoryApi=(data)=>{
  return instance({
    url: `/api/category/addCategory`,
    method: 'post',
    data
  })
}
/**
 * 删除分类信息
 * @param ids
 * @returns {Promise<AxiosResponse<any>> | *}
 * @constructor
 */
export const DeleteCategoriesApi=(ids)=>{
  return instance({
    url: `/api/category/delete`,
    method: 'delete',
    params:{ids}
  })
}

/**
 * 根据id获取分类信息
 * @param id
 * @returns {Promise<AxiosResponse<any>> | *}
 * @constructor
 */
export  const  GetCategoryByIdApi=(id)=>{
  return instance({
    url: `/api/category/${id}`,
    method: 'get',
  })
}
export  const  GetAllCategoryApi=()=>{
  return instance({
    url: `/api/category/all`,
    method: 'get',
  })
}
/**
 * 根据name获取分类信息
 * @param id
 * @returns {Promise<AxiosResponse<any>> | *}
 * @constructor
 */
export  const  GetCategoryByNameApi=(name)=>{
  return instance({
    url: `/api/category/getByName`,
    method: 'get',
    params:{name}
  })
}
/**
 * 修改分类信息
 * @returns {*}
 * @constructor
 * @param data
 */
export  const UpdateCategoryApi=(data)=>{
  return instance({
    url:'/api/category/updateCategory',
    method:'put',
    data
  })
}
